package thread;

import com.sun.org.apache.xerces.internal.xs.ShortList;

import java.util.*;

public class SyncDemo4 {
    public static void main(String[] args) {
        //List<Integer> c=new ArrayList<Integer>();
        //List<Integer> c = new LinkedList<Integer>();
        //Set<Integer> c = new HashSet<Integer>();
        //Set<Integer> c = new LinkedHashSet<>();
        List<Integer> c = Collections.synchronizedList(new ArrayList<>());


        Thread t1 = new Thread(){
            public void run(){
                for(int i=1;i<=1000;i++){
                    c.add(i);
                }
            }
        };

        Thread t2 = new Thread(){
            public void run(){
                for(int i=1;i<=1000;i++){
                    c.add(i);
                }
            }
        };

        t1.start();
        t2.start();


        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(c.size());
    }
}
